home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / standard.txt (.txt) < prev    next >
GNU Info File  |  1993-07-18  |  67KB  |  1,257 lines

  1. This is Info file standards.info, produced by Makeinfo-1.55 from the
  2. input file standards.texi.
  3.    Copyright (C) 1992, 1993 Free Software Foundation Permission is
  4. granted to make and distribute verbatim copies of this manual provided
  5. the copyright notice and this permission notice are preserved on all
  6. copies.
  7.    Permission is granted to copy and distribute modified versions of
  8. this manual under the conditions for verbatim copying, provided that
  9. the entire resulting derived work is distributed under the terms of a
  10. permission notice identical to this one.
  11.    Permission is granted to copy and distribute translations of this
  12. manual into another language, under the above conditions for modified
  13. versions, except that this permission notice may be stated in a
  14. translation approved by the Free Software Foundation.
  15. File: standards.info,  Node: Top,  Next: Reading Non-Free Code,  Prev: (dir),  Up: (dir)
  16. Version
  17. *******
  18.    Last updated 03 Feb 1993.
  19. * Menu:
  20. * Reading Non-Free Code::    Referring to Proprietary Programs
  21. * Contributions::        Accepting Contributions
  22. * Change Logs::            Recording Changes
  23. * Compatibility::        Compatibility with Other Implementations
  24. * Makefile Conventions::    Makefile Conventions
  25. * Configuration::        How Configuration Should Work
  26. * Source Language::        Using Languages Other Than C
  27. * Formatting::            Formatting Your Source Code
  28. * Comments::            Commenting Your Work
  29. * Syntactic Conventions::    Clean Use of C Constructs
  30. * Names::            Naming Variables and Functions
  31. * Using Extensions::        Using Non-standard Features
  32. * Semantics::            Program Behaviour for All Programs
  33. * Errors::            Formatting Error Messages
  34. * Libraries::            Library Behaviour
  35. * Portability::            Portability As It Applies to GNU
  36. * User Interfaces::        Standards for Command Line Interfaces
  37. * Documentation::        Documenting Programs
  38. * Releases::            Making Releases
  39. File: standards.info,  Node: Reading Non-Free Code,  Next: Contributions,  Prev: Top,  Up: Top
  40. Referring to Proprietary Programs
  41. *********************************
  42.    Don't in any circumstances refer to Unix source code for or during
  43. your work on GNU!  (Or to any other proprietary programs.)
  44.    If you have a vague recollection of the internals of a Unix program,
  45. this does not absolutely mean you can't write an imitation of it, but
  46. do try to organize the imitation internally along different lines,
  47. because this is likely to make the details of the Unix version
  48. irrelevant and dissimilar to your results.
  49.    For example, Unix utilities were generally optimized to minimize
  50. memory use; if you go for speed instead, your program will be very
  51. different.  You could keep the entire input file in core and scan it
  52. there instead of using stdio.  Use a smarter algorithm discovered more
  53. recently than the Unix program.  Eliminate use of temporary files.  Do
  54. it in one pass instead of two (we did this in the assembler).
  55.    Or, on the contrary, emphasize simplicity instead of speed.  For some
  56. applications, the speed of today's computers makes simpler algorithms
  57. adequate.
  58.    Or go for generality.  For example, Unix programs often have static
  59. tables or fixed-size strings, which make for arbitrary limits; use
  60. dynamic allocation instead.  Make sure your program handles NULs and
  61. other funny characters in the input files.  Add a programming language
  62. for extensibility and write part of the program in that language.
  63.    Or turn some parts of the program into independently usable
  64. libraries.  Or use a simple garbage collector instead of tracking
  65. precisely when to free memory, or use a new GNU facility such as
  66. obstacks.
  67. File: standards.info,  Node: Contributions,  Next: Change Logs,  Prev: Reading Non-Free Code,  Up: Top
  68. Accepting Contributions
  69. ***********************
  70.    If someone else sends you a piece of code to add to the program you
  71. are working on, we need legal papers to use it--the same sort of legal
  72. papers we will need to get from you.  *Each* significant contributor to
  73. a program must sign some sort of legal papers in order for us to have
  74. clear title to the program.  The main author alone is not enough.
  75.    So, before adding in any contributions from other people, tell us so
  76. we can arrange to get the papers.  Then wait until we tell you that we
  77. have received the signed papers, before you actually use the
  78. contribution.
  79.    This applies both before you release the program and afterward.  If
  80. you receive diffs to fix a bug, and they make significant change, we
  81. need legal papers for it.
  82.    You don't need papers for changes of a few lines here or there, since
  83. they are not significant for copyright purposes.  Also, you don't need
  84. papers if all you get from the suggestion is some ideas, not actual code
  85. which you use.  For example, if you write a different solution to the
  86. problem, you don't need to get papers.
  87.    I know this is frustrating; it's frustrating for us as well.  But if
  88. you don't wait, you are going out on a limb--for example, what if the
  89. contributor's employer won't sign a disclaimer?  You might have to take
  90. that code out again!
  91.    The very worst thing is if you forget to tell us about the other
  92. contributor.  We could be very embarrassed in court some day as a
  93. result.
  94. File: standards.info,  Node: Change Logs,  Next: Compatibility,  Prev: Contributions,  Up: Top
  95. Change Logs
  96. ***********
  97.    Keep a change log for each directory, describing the changes made to
  98. source files in that directory.  The purpose of this is so that people
  99. investigating bugs in the future will know about the changes that might
  100. have introduced the bug.  Often a new bug can be found by looking at
  101. what was recently changed.  More importantly, change logs can help
  102. eliminate conceptual inconsistencies between different parts of a
  103. program; they can give you a history of how the conflicting concepts
  104. arose.
  105.    Use the Emacs command `M-x add-change' to start a new entry in the
  106. change log.  An entry should have an asterisk, the name of the changed
  107. file, and then in parentheses the name of the changed functions,
  108. variables or whatever, followed by a colon.  Then describe the changes
  109. you made to that function or variable.
  110.    Separate unrelated entries with blank lines.  When two entries
  111. represent parts of the same change, so that they work together, then
  112. don't put blank lines between them.  Then you can omit the file name
  113. and the asterisk when successive entries are in the same file.
  114.    Here are some examples:
  115.      * register.el (insert-register): Return nil.
  116.      (jump-to-register): Likewise.
  117.      
  118.      * sort.el (sort-subr): Return nil.
  119.      
  120.      * tex-mode.el (tex-bibtex-file, tex-file, tex-region):
  121.      Restart the tex shell if process is gone or stopped.
  122.      (tex-shell-running): New function.
  123.      
  124.      * expr.c (store_one_arg): Round size up for move_block_to_reg.
  125.      (expand_call): Round up when emitting USE insns.
  126.      * stmt.c (assign_parms): Round size up for move_block_from_reg.
  127.    There's no need to describe here the full purpose of the changes or
  128. how they work together.  It is better to put this explanation in
  129. comments in the code.  That's why just "New function" is enough; there
  130. is a comment with the function in the source to explain what it does.
  131.    However, sometimes it is useful to write one line to describe the
  132. overall purpose of a large batch of changes.
  133.    You can think of the change log as a conceptual "undo list" which
  134. explains how earlier versions were different from the current version.
  135. People can see the current version; they don't need the change log to
  136. tell them what is in it.  What they want from a change log is a clear
  137. explanation of how the earlier version differed.
  138.    When you change the calling sequence of a function in a simple
  139. fashion, and you change all the callers of the function, there is no
  140. need to make individual entries for all the callers.  Just write in the
  141. entry for the function being called, "All callers changed."
  142.    When you change just comments or doc strings, it is enough to write
  143. an entry for the file, without mentioning the functions.  Write just,
  144. "Doc fix."  There's no need to keep a change log for documentation
  145. files.  This is because documentation is not susceptible to bugs that
  146. are hard to fix.  Documentation does not consist of parts that must
  147. interact in a precisely engineered fashion; to correct an error, you
  148. need not know the history of the erroneous passage.
  149. File: standards.info,  Node: Compatibility,  Next: Makefile Conventions,  Prev: Change Logs,  Up: Top
  150. Compatibility with Other Implementations
  151. ****************************************
  152.    With certain exceptions, utility programs and libraries for GNU
  153. should be upward compatible with those in Berkeley Unix, and upward
  154. compatible with ANSI C if ANSI C specifies their behavior, and upward
  155. compatible with POSIX if POSIX specifies their behavior.
  156.    When these standards conflict, it is useful to offer compatibility
  157. modes for each of them.
  158.    ANSI C and POSIX prohibit many kinds of extensions.  Feel free to
  159. make the extensions anyway, and include a `--ansi' or `--compatible'
  160. option to turn them off.  However, if the extension has a significant
  161. chance of breaking any real programs or scripts, then it is not really
  162. upward compatible.  Try to redesign its interface.
  163.    When a feature is used only by users (not by programs or command
  164. files), and it is done poorly in Unix, feel free to replace it
  165. completely with something totally different and better.  (For example,
  166. vi is replaced with Emacs.)  But it is nice to offer a compatible
  167. feature as well.  (There is a free vi clone, so we offer it.)
  168.    Additional useful features not in Berkeley Unix are welcome.
  169. Additional programs with no counterpart in Unix may be useful, but our
  170. first priority is usually to duplicate what Unix already has.
  171. File: standards.info,  Node: Makefile Conventions,  Next: Configuration,  Prev: Compatibility,  Up: Top
  172. Makefile Conventions
  173. ********************
  174.    This chapter describes conventions for writing the Makefiles for GNU
  175. programs.
  176. * Menu:
  177. * Makefile Basics::
  178. * Utilities in Makefiles::
  179. * Standard Targets::
  180. * Command Variables::
  181. * Directory Variables::
  182. File: standards.info,  Node: Makefile Basics,  Next: Utilities in Makefiles,  Up: Makefile Conventions
  183. General Conventions for Makefiles
  184. =================================
  185.    Every Makefile should contain this line:
  186.      SHELL = /bin/sh
  187. to avoid trouble on systems where the `SHELL' variable might be
  188. inherited from the environment.  (This is never a problem with GNU
  189. `make'.)
  190.    Don't assume that `.' is in the path for command execution.  When
  191. you need to run programs that are a part of your package during the
  192. make, please make sure that it uses `./' if the program is built as
  193. part of the make or `$(srcdir)/' if the file is an unchanging part of
  194. the source code.  Without one of these prefixes, the current search
  195. path is used.
  196.    The distinction between `./' and `$(srcdir)/' is important when
  197. using the `--srcdir' option to `configure'.  A rule of the form:
  198.      foo.1 : foo.man sedscript
  199.              sed -e sedscript foo.man > foo.1
  200. will fail when the current directory is not the source directory,
  201. because `foo.man' and `sedscript' are not in the current directory.
  202.    When using GNU `make', relying on `VPATH' to find the source file
  203. will work in the case where there is a single dependency file, since
  204. the `make' automatic variable `$<' will represent the source file
  205. wherever it is.  (Many versions of `make' set `$<' only in implicit
  206. rules.)  A makefile target like
  207.      foo.o : bar.c
  208.              $(CC) -I. -I$(srcdir) $(CFLAGS) -c bar.c -o foo.o
  209. should instead be written as
  210.      foo.o : bar.c
  211.              $(CC) $(CFLAGS) $< -o $@
  212. in order to allow `VPATH' to work correctly.  When the target has
  213. multiple dependencies, using an explicit `$(srcdir)' is the easiest way
  214. to make the rule work well.  For example, the target above for `foo.1'
  215. is best written as:
  216.      foo.1 : foo.man sedscript
  217.              sed -s $(srcdir)/sedscript $(srcdir)/foo.man > foo.1
  218. File: standards.info,  Node: Utilities in Makefiles,  Next: Standard Targets,  Prev: Makefile Basics,  Up: Makefile Conventions
  219. Utilities in Makefiles
  220. ======================
  221.    Write the Makefile commands (and any shell scripts, such as
  222. `configure') to run in `sh', not in `csh'.  Don't use any special
  223. features of `ksh' or `bash'.
  224.    The `configure' script and the Makefile rules for building and
  225. installation should not use any utilities directly except these:
  226.      cat cmp cp echo egrep expr grep
  227.      ln mkdir mv pwd rm rmdir sed test touch
  228.    Stick to the generally supported options for these programs.  For
  229. example, don't use `mkdir -p', convenient as it may be, because most
  230. systems don't support it.
  231.    The Makefile rules for building and installation can also use
  232. compilers and related programs, but should do so via `make' variables
  233. so that the user can substitute alternatives.  Here are some of the
  234. programs we mean:
  235.      ar bison cc flex install ld lex
  236.      make makeinfo ranlib texi2dvi yacc
  237.    When you use `ranlib', you should test whether it exists, and run it
  238. only if it exists, so that the distribution will work on systems that
  239. don't have `ranlib'.
  240.    If you use symbolic links, you should implement a fallback for
  241. systems that don't have symbolic links.
  242.    It is ok to use other utilities in Makefile portions (or scripts)
  243. intended only for particular systems where you know those utilities to
  244. exist.
  245. File: standards.info,  Node: Standard Targets,  Next: Command Variables,  Prev: Utilities in Makefiles,  Up: Makefile Conventions
  246. Standard Targets for Users
  247. ==========================
  248.    All GNU programs should have the following targets in their
  249. Makefiles:
  250. `all'
  251.      Compile the entire program.  This should be the default target.
  252.      This target need not rebuild any documentation files; info files
  253.      should normally be included in the distribution, and DVI files
  254.      should be made only when explicitly asked for.
  255. `install'
  256.      Compile the program and copy the executables, libraries, and so on
  257.      to the file names where they should reside for actual use.  If
  258.      there is a simple test to verify that a program is properly
  259.      installed then run that test.
  260.      Use `-' before any command for installing a man page, so that
  261.      `make' will ignore any errors.  This is in case there are systems
  262.      that don't have the Unix man page documentation system installed.
  263.      In the future, when we have a standard way of installing info
  264.      files, `install' targets will be the proper place to do so.
  265. `uninstall'
  266.      Delete all the installed files that the `install' target would
  267.      create (but not the noninstalled files such as `make all' would
  268.      create).
  269. `clean'
  270.      Delete all files from the current directory that are normally
  271.      created by building the program.  Don't delete the files that
  272.      record the configuration.  Also preserve files that could be made
  273.      by building, but normally aren't because the distribution comes
  274.      with them.
  275.      Delete `.dvi' files here if they are not part of the distribution.
  276. `distclean'
  277.      Delete all files from the current directory that are created by
  278.      configuring or building the program.  If you have unpacked the
  279.      source and built the program without creating any other files,
  280.      `make distclean' should leave only the files that were in the
  281.      distribution.
  282. `mostlyclean'
  283.      Like `clean', but may refrain from deleting a few files that people
  284.      normally don't want to recompile.  For example, the `mostlyclean'
  285.      target for GCC does not delete `libgcc.a', because recompiling it
  286.      is rarely necessary and takes a lot of time.
  287. `realclean'
  288.      Delete everything from the current directory that can be
  289.      reconstructed with this Makefile.  This typically includes
  290.      everything deleted by distclean, plus more: C source files
  291.      produced by Bison, tags tables, info files, and so on.
  292.      One exception, however: `make realclean' should not delete
  293.      `configure' even if `configure' can be remade using a rule in the
  294.      Makefile.  More generally, `make realclean' should not delete
  295.      anything that needs to exist in order to run `configure' and then
  296.      begin to build the program.
  297. `TAGS'
  298.      Update a tags table for this program.
  299. `info'
  300.      Generate any info files needed.  The best way to write the rules
  301.      is as follows:
  302.           info:  foo.info
  303.           
  304.           foo.info: $(srcdir)/foo.texi $(srcdir)/chap1.texi $(srcdir)/chap2.texi
  305.                   $(MAKEINFO) $(srcdir)/foo.texi
  306.      You must define the variable `MAKEINFO' in the Makefile.  It
  307.      should run the Makeinfo program, which is part of the Texinfo2
  308.      distribution.
  309. `dvi'
  310.      Generate DVI files for all TeXinfo documentation.  For example:
  311.           dvi: foo.dvi
  312.           
  313.           foo.dvi: $(srcdir)/foo.texi $(srcdir)/chap1.texi $(srcdir)/chap2.texi
  314.                   $(TEXI2DVI) $(srcdir)/foo.texi
  315.      You must define the variable `TEXI2DVI' in the Makefile.  It should
  316.      run the program `texi2dvi', which is part of the Texinfo2
  317.      distribution.  Alternatively, write just the dependencies, and
  318.      allow GNU Make to provide the command.
  319. `dist'
  320.      Create a distribution tar file for this program.  The tar file
  321.      should be set up so that the file names in the tar file start with
  322.      a subdirectory name which is the name of the package it is a
  323.      distribution for.  This name can include the version number.
  324.      For example, the distribution tar file of GCC version 1.40 unpacks
  325.      into a subdirectory named `gcc-1.40'.
  326.      The easiest way to do this is to create a subdirectory
  327.      appropriately named, use `ln' or `cp' to install the proper files
  328.      in it, and then `tar' that subdirectory.
  329.      The `dist' target should explicitly depend on all non-source files
  330.      that are in the distribution, to make sure they are up to date in
  331.      the distribution.  *Note Making Releases: (standards)Releases.
  332. `check'
  333.      Perform self-tests (if any).  The user must build the program
  334.      before running the tests, but need not install the program; you
  335.      should write the self-tests so that they work when the program is
  336.      built but not installed.
  337.    The following target is suggested as a conventional name, for
  338. programs in which it is useful.
  339. `installcheck'
  340.      Perform installation tests (if any).  The user must build and
  341.      install the program before running the tests.  You should not
  342.      assume that `$(bindir)' is in the search path.
  343. `installdirs'
  344.      It's useful to add a target named `installdirs' to create the
  345.      directories where files are installed, and their parent
  346.      directories.  You can use a rule like this:
  347.           # Make sure all installation directories, e.g. $(bindir) actually exist by
  348.           # making them if necessary.
  349.           installdirs:
  350.                   for file in $(bindir) $(datadir) $(libdir) $(infodir) $(mandir) ; do \
  351.                      oIFS="$${IFS}"; IFS='/'; set - $${file}; IFS="$${oIFS}"; \
  352.                      pathcomp=''; test ".$${1}" = "." && shift; \
  353.                      while test $$# -ne 0 ; do \
  354.                        pathcomp="$${pathcomp}/$${1}"; shift; \
  355.                        if test ! -d "$${pathcomp}"; then \
  356.                           echo "making directory $$pathcomp" 1>&2 ; \
  357.                           mkdir "$${pathcomp}"; \
  358.                        fi; \
  359.                      done; \
  360.                   done
  361. File: standards.info,  Node: Command Variables,  Next: Directory Variables,  Prev: Standard Targets,  Up: Makefile Conventions
  362. Variables for Specifying Commands
  363. =================================
  364.    Makefiles should provide variables for overriding certain commands,
  365. options, and so on.
  366.    In particular, you should run most utility programs via variables.
  367. Thus, if you use Bison, have a variable named `BISON' whose default
  368. value is set with `BISON = bison', and refer to it with `$(BISON)'
  369. whenever you need to use Bison.
  370.    File management utilities such as `ln', `rm', `mv', and so on, need
  371. not be referred to through variables in this way, since users don't
  372. need to replace them with other programs.
  373.    Each program-name variable should come with an options variable that
  374. is used to supply options to the program.  Append `FLAGS' to the
  375. program-name variable name to get the options variable name--for
  376. example, `BISONFLAGS'.  (The name `CFLAGS' is an exception to this
  377. rule, but we keep it because it is standard.)  Use `CPPFLAGS' in any
  378. compilation command that runs the preprocessor, and use `LDFLAGS' in
  379. any compilation command that does linking as well as in any direct use
  380. of `ld'.
  381.    If there are C compiler options that *must* be used for proper
  382. compilation of certain files, do not include them in `CFLAGS'.  Users
  383. expect to be able to specify `CFLAGS' freely themselves.  Instead,
  384. arrange to pass the necessary options to the C compiler independently
  385. of `CFLAGS', by writing them explicitly in the compilation commands or
  386. by defining an implicit rule, like this:
  387.      CFLAGS = -g
  388.      ALL_CFLAGS = -I. $(CFLAGS)
  389.      .c.o:
  390.              $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
  391.    Do include the `-g' option in `CFLAGS', because that is not
  392. *required* for proper compilation.  You can consider it a default that
  393. is only recommended.  If the package is set up so that it is compiled
  394. with GCC by default, then you might as well include `-O' in the default
  395. value of `CFLAGS' as well.
  396.    Put `CFLAGS' last in the compilation command, after other variables
  397. containing compiler options, so the user can use `CFLAGS' to override
  398. the others.
  399.    Every Makefile should define the variable `INSTALL', which is the
  400. basic command for installing a file into the system.
  401.    Every Makefile should also define variables `INSTALL_PROGRAM' and
  402. `INSTALL_DATA'.  (The default for each of these should be
  403. `$(INSTALL)'.)  Then it should use those variables as the commands for
  404. actual installation, for executables and nonexecutables respectively.
  405. Use these variables as follows:
  406.      $(INSTALL_PROGRAM) foo $(bindir)/foo
  407.      $(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a
  408. Always use a file name, not a directory name, as the second argument of
  409. the installation commands.  Use a separate command for each file to be
  410. installed.
  411. File: standards.info,  Node: Directory Variables,  Prev: Command Variables,  Up: Makefile Conventions
  412. Variables for Installation Directories
  413. ======================================
  414.    Installation directories should always be named by variables, so it
  415. is easy to install in a nonstandard place.  The standard names for these
  416. variables are:
  417. `prefix'
  418.      A prefix used in constructing the default values of the variables
  419.      listed below.  The default value of `prefix' should be `/usr/local'
  420.      (at least for now).
  421. `exec_prefix'
  422.      A prefix used in constructing the default values of the some of the
  423.      variables listed below.  The default value of `exec_prefix' should
  424.      be `$(prefix)'.
  425.      Generally, `$(exec_prefix)' is used for directories that contain
  426.      machine-specific files (such as executables and subroutine
  427.      libraries), while `$(prefix)' is used directly for other
  428.      directories.
  429. `bindir'
  430.      The directory for installing executable programs that users can
  431.      run.  This should normally be `/usr/local/bin', but write it as
  432.      `$(exec_prefix)/bin'.
  433. `libdir'
  434.      The directory for installing executable files to be run by the
  435.      program rather than by users.  Object files and libraries of
  436.      object code should also go in this directory.  The idea is that
  437.      this directory is used for files that pertain to a specific
  438.      machine architecture, but need not be in the path for commands.
  439.      The value of `libdir' should normally be `/usr/local/lib', but
  440.      write it as `$(exec_prefix)/lib'.
  441. `datadir'
  442.      The directory for installing read-only data files which the
  443.      programs refer to while they run.  This directory is used for
  444.      files which are independent of the type of machine being used.
  445.      This should normally be `/usr/local/lib', but write it as
  446.      `$(prefix)/lib'.
  447. `statedir'
  448.      The directory for installing data files which the programs modify
  449.      while they run.  These files should be independent of the type of
  450.      machine being used, and it should be possible to share them among
  451.      machines at a network installation.  This should normally be
  452.      `/usr/local/lib', but write it as `$(prefix)/lib'.
  453. `includedir'
  454.      The directory for installing header files to be included by user
  455.      programs with the C `#include' preprocessor directive.  This
  456.      should normally be `/usr/local/include', but write it as
  457.      `$(prefix)/include'.
  458.      Most compilers other than GCC do not look for header files in
  459.      `/usr/local/include'.  So installing the header files this way is
  460.      only useful with GCC.  Sometimes this is not a problem because some
  461.      libraries are only really intended to work with GCC.  But some
  462.      libraries are intended to work with other compilers.  They should
  463.      install their header files in two places, one specified by
  464.      `includedir' and one specified by `oldincludedir'.
  465. `oldincludedir'
  466.      The directory for installing `#include' header files for use with
  467.      compilers other than GCC.  This should normally be `/usr/include'.
  468.      The Makefile commands should check whether the value of
  469.      `oldincludedir' is empty.  If it is, they should not try to use
  470.      it; they should cancel the second installation of the header files.
  471.      A package should not replace an existing header in this directory
  472.      unless the header came from the same package.  Thus, if your Foo
  473.      package provides a header file `foo.h', then it should install the
  474.      header file in the `oldincludedir' directory if either (1) there
  475.      is no `foo.h' there or (2) the `foo.h' that exists came from the
  476.      Foo package.
  477.      The way to tell whether `foo.h' came from the Foo package is to put
  478.      a magic string in the file--part of a comment--and grep for that
  479.      string.
  480. `mandir'
  481.      The directory for installing the man pages (if any) for this
  482.      package.  It should include the suffix for the proper section of
  483.      the manual--usually `1' for a utility.
  484. `man1dir'
  485.      The directory for installing section 1 man pages.
  486. `man2dir'
  487.      The directory for installing section 2 man pages.
  488. `...'
  489.      Use these names instead of `mandir' if the package needs to
  490.      install man pages in more than one section of the manual.
  491.      *Don't make the primary documentation for any GNU software be a
  492.      man page.  Write a manual in Texinfo instead.  Man pages are just
  493.      for the sake of people running GNU software on Unix, which is a
  494.      secondary application only.*
  495. `manext'
  496.      The file name extension for the installed man page.  This should
  497.      contain a period followed by the appropriate digit.
  498. `infodir'
  499.      The directory for installing the info files for this package.  By
  500.      default, it should be `/usr/local/info', but it should be written
  501.      as `$(prefix)/info'.
  502. `srcdir'
  503.      The directory for the sources being compiled.  The value of this
  504.      variable is normally inserted by the `configure' shell script.
  505.    For example:
  506.      # Common prefix for installation directories.
  507.      # NOTE: This directory must exist when you start the install.
  508.      prefix = /usr/local
  509.      exec_prefix = $(prefix)
  510.      # Where to put the executable for the command `gcc'.
  511.      bindir = $(exec_prefix)/bin
  512.      # Where to put the directories used by the compiler.
  513.      libdir = $(exec_prefix)/lib
  514.      # Where to put the Info files.
  515.      infodir = $(prefix)/info
  516.    If your program installs a large number of files into one of the
  517. standard user-specified directories, it might be useful to group them
  518. into a subdirectory particular to that program.  If you do this, you
  519. should write the `install' rule to create these subdirectories.
  520.    Do not expect the user to include the subdirectory name in the value
  521. of any of the variables listed above.  The idea of having a uniform set
  522. of variable names for installation directories is to enable the user to
  523. specify the exact same values for several different GNU packages.  In
  524. order for this to be useful, all the packages must be designed so that
  525. they will work sensibly when the user does so.
  526. File: standards.info,  Node: Configuration,  Next: Source Language,  Prev: Makefile Conventions,  Up: Top
  527. How Configuration Should Work
  528. *****************************
  529.    Each GNU distribution should come with a shell script named
  530. `configure'.  This script is given arguments which describe the kind of
  531. machine and system you want to compile the program for.
  532.    The `configure' script must record the configuration options so that
  533. they affect compilation.
  534.    One way to do this is to make a link from a standard name such as
  535. `config.h' to the proper configuration file for the chosen system.  If
  536. you use this technique, the distribution should *not* contain a file
  537. named `config.h'.  This is so that people won't be able to build the
  538. program without configuring it first.
  539.    Another thing that `configure' can do is to edit the Makefile.  If
  540. you do this, the distribution should *not* contain a file named
  541. `Makefile'.  Instead, include a file `Makefile.in' which contains the
  542. input used for editing.  Once again, this is so that people won't be
  543. able to build the program without configuring it first.
  544.    If `configure' does write the `Makefile', then `Makefile' should
  545. have a target named `Makefile' which causes `configure' to be rerun,
  546. setting up the same configuration that was set up last time.  The files
  547. that `configure' reads should be listed as dependencies of `Makefile'.
  548.    All the files which are output from the `configure' script should
  549. have comments at the beginning explaining that they were generated
  550. automatically using `configure'.  This is so that users won't think of
  551. trying to edit them by hand.
  552.    The `configure' script should write a file named `config.status'
  553. which describes which configuration options were specified when the
  554. program was last configured.  This file should be a shell script which,
  555. if run, will recreate the same configuration.
  556.    The `configure' script should accept an option of the form
  557. `--srcdir=DIRNAME' to specify the directory where sources are found (if
  558. it is not the current directory).  This makes it possible to build the
  559. program in a separate directory, so that the actual source directory is
  560. not modified.
  561.    If the user does not specify `--srcdir', then `configure' should
  562. check both `.' and `..' to see if it can find the sources.  If it finds
  563. the sources in one of these places, it should use them from there.
  564. Otherwise, it should report that it cannot find the sources, and should
  565. exit with nonzero status.
  566.    Usually the easy way to support `--srcdir' is by editing a
  567. definition of `VPATH' into the Makefile.  Some rules may need to refer
  568. explicitly to the specified source directory.  To make this possible,
  569. `configure' can add to the Makefile a variable named `srcdir' whose
  570. value is precisely the specified directory.
  571.    The `configure' script should also take an argument which specifies
  572. the type of system to build the program for.  This argument should look
  573. like this:
  574.      CPU-COMPANY-SYSTEM
  575.    For example, a Sun 3 might be `m68k-sun-sunos4.1'.
  576.    The `configure' script needs to be able to decode all plausible
  577. alternatives for how to describe a machine.  Thus, `sun3-sunos4.1'
  578. would be a valid alias.  So would `sun3-bsd4.2', since SunOS is
  579. basically BSD and no other BSD system is used on a Sun.  For many
  580. programs, `vax-dec-ultrix' would be an alias for `vax-dec-bsd', simply
  581. because the differences between Ultrix and BSD are rarely noticeable,
  582. but a few programs might need to distinguish them.
  583.    There is a shell script called `config.sub' that you can use as a
  584. subroutine to validate system types and canonicalize aliases.
  585.    Other options are permitted to specify in more detail the software
  586. or hardware are present on the machine:
  587. `--with-PACKAGE'
  588.      The package PACKAGE will be installed, so configure this package
  589.      to work with PACKAGE.
  590.      Possible values of PACKAGE include `x', `gnu-as' (or `gas'),
  591.      `gnu-ld', `gnu-libc', and `gdb'.
  592. `--nfp'
  593.      The target machine has no floating point processor.
  594. `--gas'
  595.      The target machine assembler is GAS, the GNU assembler.  This is
  596.      obsolete; use `--with-gnu-as' instead.
  597. `--x'
  598.      The target machine has the X Window System installed.  This is
  599.      obsolete; use `--with-x' instead.
  600.    All `configure' scripts should accept all of these "detail" options,
  601. whether or not they make any difference to the particular package at
  602. hand.  In particular, they should accept any option that starts with
  603. `--with-'.  This is so users will be able to configure an entire GNU
  604. source tree at once with a single set of options.
  605.    Packages that perform part of compilation may support
  606. cross-compilation.  In such a case, the host and target machines for
  607. the program may be different.  The `configure' script should normally
  608. treat the specified type of system as both the host and the target,
  609. thus producing a program which works for the same type of machine that
  610. it runs on.
  611.    The way to build a cross-compiler, cross-assembler, or what have
  612. you, is to specify the option `--host=HOSTTYPE' when running
  613. `configure'.  This specifies the host system without changing the type
  614. of target system.  The syntax for HOSTTYPE is the same as described
  615. above.
  616.    Programs for which cross-operation is not meaningful need not accept
  617. the `--host' option, because configuring an entire operating system for
  618. cross-operation is not a meaningful thing.
  619.    Some programs have ways of configuring themselves automatically.  If
  620. your program is set up to do this, your `configure' script can simply
  621. ignore most of its arguments.
  622. File: standards.info,  Node: Source Language,  Next: Formatting,  Prev: Configuration,  Up: Top
  623. Using Languages Other Than C
  624. ****************************
  625.    Using a language other than C is like using a non-standard feature:
  626. it will cause trouble for users.  Even if GCC supports the other
  627. language, users may find it inconvenient to have to install the
  628. compiler for that other language in order to build your program.  So
  629. please write in C.
  630.    There are three exceptions for this rule:
  631.    * It is okay to use a special language if the same program contains
  632.      an interpreter for that language.
  633.      Thus, it is not a problem that GNU Emacs contains code written in
  634.      Emacs Lisp, because it comes with a Lisp interpreter.
  635.    * It is okay to use another language in a tool specifically intended
  636.      for use with that language.
  637.      This is okay because the only people who want to build the tool
  638.      will be those who have installed the other language anyway.
  639.    * If an application is not of extremely widespread interest, then
  640.      perhaps it's not important if the application is inconvenient to
  641.      install.
  642. File: standards.info,  Node: Formatting,  Next: Comments,  Prev: Source Language,  Up: Top
  643. Formatting Your Source Code
  644. ***************************
  645.    It is important to put the open-brace that starts the body of a C
  646. function in column zero, and avoid putting any other open-brace or
  647. open-parenthesis or open-bracket in column zero.  Several tools look
  648. for open-braces in column zero to find the beginnings of C functions.
  649. These tools will not work on code not formatted that way.
  650.    It is also important for function definitions to start the name of
  651. the function in column zero.  This helps people to search for function
  652. definitions, and may also help certain tools recognize them.  Thus, the
  653. proper format is this:
  654.      static char *
  655.      concat (s1, s2)        /* Name starts in column zero here */
  656.           char *s1, *s2;
  657.      {                     /* Open brace in column zero here */
  658.        ...
  659.      }
  660. or, if you want to use ANSI C, format the definition like this:
  661.      static char *
  662.      concat (char *s1, char *s2)
  663.      {
  664.        ...
  665.      }
  666.    In ANSI C, if the arguments don't fit nicely on one line, split it
  667. like this:
  668.      int
  669.      lots_of_args (int an_integer, long a_long, short a_short,
  670.                    double a_double, float a_float)
  671.      ...
  672.    For the body of the function, we prefer code formatted like this:
  673.      if (x < foo (y, z))
  674.        haha = bar[4] + 5;
  675.      else
  676.        {
  677.          while (z)
  678.            {
  679.              haha += foo (z, z);
  680.              z--;
  681.            }
  682.          return ++x + bar ();
  683.        }
  684.    We find it easier to read a program when it has spaces before the
  685. open-parentheses and after the commas.  Especially after the commas.
  686.    When you split an expression into multiple lines, split it before an
  687. operator, not after one.  Here is the right way:
  688.      if (foo_this_is_long && bar > win (x, y, z)
  689.          && remaining_condition)
  690.    Try to avoid having two operators of different precedence at the same
  691. level of indentation.  For example, don't write this:
  692.      mode = (inmode[j] == VOIDmode
  693.              || GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])
  694.              ? outmode[j] : inmode[j]);
  695.    Instead, use extra parentheses so that the indentation shows the
  696. nesting:
  697.      mode = ((inmode[j] == VOIDmode
  698.               || (GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])))
  699.              ? outmode[j] : inmode[j]);
  700.    Insert extra parentheses so that Emacs will indent the code properly.
  701. For example, the following indentation looks nice if you do it by hand,
  702. but Emacs would mess it up:
  703.      v = rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
  704.          + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000;
  705.    But adding a set of parentheses solves the problem:
  706.      v = (rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
  707.           + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000);
  708.    Format do-while statements like this:
  709.      do
  710.        {
  711.          a = foo (a);
  712.        }
  713.      while (a > 0);
  714.    Please use formfeed characters (control-L) to divide the program into
  715. pages at logical places (but not within a function).  It does not matter
  716. just how long the pages are, since they do not have to fit on a printed
  717. page.  The formfeeds should appear alone on lines by themselves.
  718. File: standards.info,  Node: Comments,  Next: Syntactic Conventions,  Prev: Formatting,  Up: Top
  719. Commenting Your Work
  720. ********************
  721.    Every program should start with a comment saying briefly what it is
  722. for.  Example: `fmt - filter for simple filling of text'.
  723.    Please put a comment on each function saying what the function does,
  724. what sorts of arguments it gets, and what the possible values of
  725. arguments mean and are used for.  It is not necessary to duplicate in
  726. words the meaning of the C argument declarations, if a C type is being
  727. used in its customary fashion.  If there is anything nonstandard about
  728. its use (such as an argument of type `char *' which is really the
  729. address of the second character of a string, not the first), or any
  730. possible values that would not work the way one would expect (such as,
  731. that strings containing newlines are not guaranteed to work), be sure
  732. to say so.
  733.    Also explain the significance of the return value, if there is one.
  734.    Please put two spaces after the end of a sentence in your comments,
  735. so that the Emacs sentence commands will work.  Also, please write
  736. complete sentences and capitalize the first word.  If a lower-case
  737. identifer comes at the beginning of a sentence, don't capitalize it!
  738. Changing the spelling makes it a different identifier.  If you don't
  739. like starting a sentence with a lower case letter, write the sentence
  740. differently (e.g. "The identifier lower-case is ...").
  741.    The comment on a function is much clearer if you use the argument
  742. names to speak about the argument values.  The variable name itself
  743. should be lower case, but write it in upper case when you are speaking
  744. about the value rather than the variable itself.  Thus, "the inode
  745. number NODE_NUM" rather than "an inode".
  746.    There is usually no purpose in restating the name of the function in
  747. the comment before it, because the reader can see that for himself.
  748. There might be an exception when the comment is so long that the
  749. function itself would be off the bottom of the screen.
  750.    There should be a comment on each static variable as well, like this:
  751.      /* Nonzero means truncate lines in the display;
  752.         zero means continue them.  */
  753.      
  754.      int truncate_lines;
  755.    Every `#endif' should have a comment, except in the case of short
  756. conditionals (just a few lines) that are not nested.  The comment should
  757. state the condition of the conditional that is ending, *including its
  758. sense*.  `#else' should have a comment describing the condition *and
  759. sense* of the code that follows.  For example:
  760.      #ifdef foo
  761.        ...
  762.      #else /* not foo */
  763.        ...
  764.      #endif /* not foo */
  765. but, by contrast, write the comments this way for a `#ifndef':
  766.      #ifndef foo
  767.        ...
  768.      #else /* foo */
  769.        ...
  770.      #endif /* foo */
  771. File: standards.info,  Node: Syntactic Conventions,  Next: Names,  Prev: Comments,  Up: Top
  772. Clean Use of C Constructs
  773. *************************
  774.    Please explicitly declare all arguments to functions.  Don't omit
  775. them just because they are ints.
  776.    Declarations of external functions and functions to appear later in
  777. the source file should all go in one place near the beginning of the
  778. file (somewhere before the first function definition in the file), or
  779. else should go in a header file.  Don't put extern declarations inside
  780. functions.
  781.    It used to be common practice to use the same local variables (with
  782. names like `tem') over and over for different values within one
  783. function.  Instead of doing this, it is better declare a separate local
  784. variable for each distinct purpose, and give it a name which is
  785. meaningful.  This not only makes programs easier to understand, it also
  786. facilitates optimization by good compilers.  You can also move the
  787. declaration of each local variable into the smallest scope that includes
  788. all its uses.  This makes the program even cleaner.
  789.    Don't use local variables or parameters that shadow global
  790. identifiers.
  791.    Don't declare multiple variables in one declaration that spans lines.
  792. Start a new declaration on each line, instead.  For example, instead of
  793. this:
  794.      int    foo,
  795.             bar;
  796. write either this:
  797.      int foo, bar;
  798. or this:
  799.      int foo;
  800.      int bar;
  801. (If they are global variables, each should have a comment preceding it
  802. anyway.)
  803.    When you have an if-else statement nested in another if statement,
  804. always put braces around the if-else.  Thus, never write like this:
  805.      if (foo)
  806.        if (bar)
  807.          win ();
  808.        else
  809.          lose ();
  810. always like this:
  811.      if (foo)
  812.        {
  813.          if (bar)
  814.            win ();
  815.          else
  816.            lose ();
  817.        }
  818.    If you have an if statement nested inside of an else statement,
  819. either write `else if' on one line, like this,
  820.      if (foo)
  821.        ...
  822.      else if (bar)
  823.        ...
  824. with its then-part indented like the preceding then-part, or write the
  825. nested if within braces like this:
  826.      if (foo)
  827.        ...
  828.      else
  829.        {
  830.          if (bar)
  831.            ...
  832.        }
  833.    Don't declare both a structure tag and variables or typedefs in the
  834. same declaration.  Instead, declare the structure tag separately and
  835. then use it to declare the variables or typedefs.
  836.    Try to avoid assignments inside if-conditions.  For example, don't
  837. write this:
  838.      if ((foo = (char *) malloc (sizeof *foo)) == 0)
  839.        fatal ("virtual memory exhausted");
  840. instead, write this:
  841.      foo = (char *) malloc (sizeof *foo);
  842.      if (foo == 0)
  843.        fatal ("virtual memory exhausted");
  844.    Don't make the program ugly to placate lint.  Please don't insert any
  845. casts to void.  Zero without a cast is perfectly fine as a null pointer
  846. constant.
  847. File: standards.info,  Node: Names,  Next: Using Extensions,  Prev: Syntactic Conventions,  Up: Top
  848. Naming Variables and Functions
  849. ******************************
  850.    Please use underscores to separate words in a name, so that the Emacs
  851. word commands can be useful within them.  Stick to lower case; reserve
  852. upper case for macros and enum constants, and for name-prefixes that
  853. follow a uniform convention.
  854.    For example, you should use names like `ignore_space_change_flag';
  855. don't use names like `iCantReadThis'.
  856.    Variables that indicate whether command-line options have been
  857. specified should be named after the meaning of the option, not after
  858. the option-letter.  A comment should state both the exact meaning of
  859. the option and its letter.  For example,
  860.      /* Ignore changes in horizontal whitespace (-b).  */
  861.      int ignore_space_change_flag;
  862.    When you want to define names with constant integer values, use
  863. `enum' rather than `#define'.  GDB knows about enumeration constants.
  864.    Use file names of 14 characters or less, to avoid creating gratuitous
  865. problems on System V.
  866. File: standards.info,  Node: Using Extensions,  Next: Semantics,  Prev: Names,  Up: Top
  867. Using Non-standard Features
  868. ***************************
  869.    Many GNU facilities that already exist support a number of convenient
  870. extensions over the comparable Unix facilities.  Whether to use these
  871. extensions in implementing your program is a difficult question.
  872.    On the one hand, using the extensions can make a cleaner program.
  873. On the other hand, people will not be able to build the program unless
  874. the other GNU tools are available.  This might cause the program to
  875. work on fewer kinds of machines.
  876.    With some extensions, it might be easy to provide both alternatives.
  877. For example, you can define functions with a "keyword" `INLINE' and
  878. define that as a macro to expand into either `inline' or nothing,
  879. depending on the compiler.
  880.    In general, perhaps it is best not to use the extensions if you can
  881. straightforwardly do without them, but to use the extensions if they
  882. are a big improvement.
  883.    An exception to this rule are the large, established programs (such
  884. as Emacs) which run on a great variety of systems.  Such programs would
  885. be broken by use of GNU extensions.
  886.    Another exception is for programs that are used as part of
  887. compilation: anything that must be compiled with other compilers in
  888. order to bootstrap the GNU compilation facilities.  If these require
  889. the GNU compiler, then no one can compile them without having them
  890. installed already.  That would be no good.
  891.    Since most computer systems do not yet implement ANSI C, using the
  892. ANSI C features is effectively using a GNU extension, so the same
  893. considerations apply.  (Except for ANSI features that we discourage,
  894. such as trigraphs--don't ever use them.)
  895. File: standards.info,  Node: Semantics,  Next: Errors,  Prev: Using Extensions,  Up: Top
  896. Program Behaviour for All Programs
  897. **********************************
  898.    Avoid arbitrary limits on the length or number of *any* data
  899. structure, including filenames, lines, files, and symbols, by allocating
  900. all data structures dynamically.  In most Unix utilities, "long lines
  901. are silently truncated".  This is not acceptable in a GNU utility.
  902.    Utilities reading files should not drop NUL characters, or any other
  903. nonprinting characters *including those with codes above 0177*.  The
  904. only sensible exceptions would be utilities specifically intended for
  905. interface to certain types of printers that can't handle those
  906. characters.
  907.    Check every system call for an error return, unless you know you
  908. wish to ignore errors.  Include the system error text (from `perror' or
  909. equivalent) in *every* error message resulting from a failing system
  910. call, as well as the name of the file if any and the name of the
  911. utility.  Just "cannot open foo.c" or "stat failed" is not sufficient.
  912.    Check every call to `malloc' or `realloc' to see if it returned
  913. zero.  Check `realloc' even if you are making the block smaller; in a
  914. system that rounds block sizes to a power of 2, `realloc' may get a
  915. different block if you ask for less space.
  916.    In Unix, `realloc' can destroy the storage block if it returns zero.
  917. GNU `realloc' does not have this bug: if it fails, the original block
  918. is unchanged.  Feel free to assume the bug is fixed.  If you wish to
  919. run your program on Unix, and wish to avoid lossage in this case, you
  920. can use the GNU `malloc'.
  921.    You must expect `free' to alter the contents of the block that was
  922. freed.  Anything you want to fetch from the block, you must fetch before
  923. calling `free'.
  924.    Use `getopt_long' to decode arguments, unless the argument syntax
  925. makes this unreasonable.
  926.    When static storage is to be written in during program execution, use
  927. explicit C code to initialize it.  Reserve C initialized declarations
  928. for data that will not be changed.
  929.    Try to avoid low-level interfaces to obscure Unix data structures
  930. (such as file directories, utmp, or the layout of kernel memory), since
  931. these are less likely to work compatibly.  If you need to find all the
  932. files in a directory, use `readdir' or some other high-level interface.
  933. These will be supported compatibly by GNU.
  934.    By default, the GNU system will provide the signal handling
  935. functions of BSD and of POSIX.  So GNU software should be written to use
  936. these.
  937.    In error checks that detect "impossible" conditions, just abort.
  938. There is usually no point in printing any message.  These checks
  939. indicate the existence of bugs.  Whoever wants to fix the bugs will have
  940. to read the source code and run a debugger.  So explain the problem with
  941. comments in the source.  The relevant data will be in variables, which
  942. are easy to examine with the debugger, so there is no point moving them
  943. elsewhere.
  944. File: standards.info,  Node: Errors,  Next: Libraries,  Prev: Semantics,  Up: Top
  945. Formatting Error Messages
  946. *************************
  947.    Error messages from compilers should look like this:
  948.      SOURCE-FILE-NAME:LINENO: MESSAGE
  949.    Error messages from other noninteractive programs should look like
  950. this:
  951.      PROGRAM:SOURCE-FILE-NAME:LINENO: MESSAGE
  952. when there is an appropriate source file, or like this:
  953.      PROGRAM: MESSAGE
  954. when there is no relevant source file.
  955.    In an interactive program (one that is reading commands from a
  956. terminal), it is better not to include the program name in an error
  957. message.  The place to indicate which program is running is in the
  958. prompt or with the screen layout.  (When the same program runs with
  959. input from a source other than a terminal, it is not interactive and
  960. would do best to print error messages using the noninteractive style.)
  961.    The string MESSAGE should not begin with a capital letter when it
  962. follows a program name and/or filename.  Also, it should not end with a
  963. period.
  964.    Error messages from interactive programs, and other messages such as
  965. usage messages, should start with a capital letter.  But they should not
  966. end with a period.
  967. File: standards.info,  Node: Libraries,  Next: Portability,  Prev: Errors,  Up: Top
  968. Library Behaviour
  969. *****************
  970.    Try to make library functions reentrant.  If they need to do dynamic
  971. storage allocation, at least try to avoid any nonreentrancy aside from
  972. that of `malloc' itself.
  973.    Here are certain name conventions for libraries, to avoid name
  974. conflicts.
  975.    Choose a name prefix for the library, more than two characters long.
  976. All external function and variable names should start with this prefix.
  977. In addition, there should only be one of these in any given library
  978. member.  This usually means putting each one in a separate source file.
  979.    An exception can be made when two external symbols are always used
  980. together, so that no reasonable program could use one without the
  981. other; then they can both go in the same file.
  982.    External symbols that are not documented entry points for the user
  983. should have names beginning with `_'.  They should also contain the
  984. chosen name prefix for the library, to prevent collisions with other
  985. libraries.  These can go in the same files with user entry points if
  986. you like.
  987.    Static functions and variables can be used as you like and need not
  988. fit any naming convention.
  989. File: standards.info,  Node: Portability,  Next: User Interfaces,  Prev: Libraries,  Up: Top
  990. Portability As It Applies to GNU
  991. ********************************
  992.    Much of what is called "portability" in the Unix world refers to
  993. porting to different Unix versions.  This is a secondary consideration
  994. for GNU software, because its primary purpose is to run on top of one
  995. and only one kernel, the GNU kernel, compiled with one and only one C
  996. compiler, the GNU C compiler.  The amount and kinds of variation among
  997. GNU systems on different cpu's will be like the variation among Berkeley
  998. 4.3 systems on different cpu's.
  999.    All users today run GNU software on non-GNU systems.  So supporting a
  1000. variety of non-GNU systems is desirable; simply not paramount.  The
  1001. easiest way to achieve portability to a reasonable range of systems is
  1002. to use Autoconf.  It's unlikely that your program needs to know more
  1003. information about the host machine than Autoconf can provide, simply
  1004. because most of the programs that need such knowledge have already been
  1005. written.
  1006.    It is difficult to be sure exactly what facilities the GNU kernel
  1007. will provide, since it isn't finished yet.  Therefore, assume you can
  1008. use anything in 4.3; just avoid using the format of semi-internal data
  1009. bases (e.g., directories) when there is a higher-level alternative
  1010. (readdir).
  1011.    You can freely assume any reasonably standard facilities in the C
  1012. language, libraries or kernel, because we will find it necessary to
  1013. support these facilities in the full GNU system, whether or not we have
  1014. already done so.  The fact that there may exist kernels or C compilers
  1015. that lack these facilities is irrelevant as long as the GNU kernel and
  1016. C compiler support them.
  1017.    It remains necessary to worry about differences among cpu types, such
  1018. as the difference in byte ordering and alignment restrictions.  It's
  1019. unlikely that 16-bit machines will ever be supported by GNU, so there
  1020. is no point in spending any time to consider the possibility that an
  1021. int will be less than 32 bits.
  1022.    You can assume that all pointers have the same format, regardless of
  1023. the type they point to, and that this is really an integer.  There are
  1024. some weird machines where this isn't true, but they aren't important;
  1025. don't waste time catering to them.  Besides, eventually we will put
  1026. function prototypes into all GNU programs, and that will probably make
  1027. your program work even on weird machines.
  1028.    Since some important machines (including the 68000) are big-endian,
  1029. it is important not to assume that the address of an int object is also
  1030. the address of its least-significant byte.  Thus, don't make the
  1031. following mistake:
  1032.      int c;
  1033.      ...
  1034.      while ((c = getchar()) != EOF)
  1035.              write(file_descriptor, &c, 1);
  1036.    You can assume that it is reasonable to use a meg of memory.  Don't
  1037. strain to reduce memory usage unless it can get to that level.  If your
  1038. program creates complicated data structures, just make them in core and
  1039. give a fatal error if malloc returns zero.
  1040.    If a program works by lines and could be applied to arbitrary
  1041. user-supplied input files, it should keep only a line in memory, because
  1042. this is not very hard and users will want to be able to operate on input
  1043. files that are bigger than will fit in core all at once.
  1044. File: standards.info,  Node: User Interfaces,  Next: Documentation,  Prev: Portability,  Up: Top
  1045. Standards for Command Line Interfaces
  1046. *************************************
  1047.    Please don't make the behavior of a utility depend on the name used
  1048. to invoke it.  It is useful sometimes to make a link to a utility with
  1049. a different name, and that should not change what it does.
  1050.    Instead, use a run time option or a compilation switch or both to
  1051. select among the alternate behaviors.
  1052.    Likewise, please don't make the behavior of the program depend on the
  1053. type of output device it is used with.  Device independence is an
  1054. important principle of the system's design; do not compromise it merely
  1055. to save someone from typing an option now and then.
  1056.    If you think one behavior is most useful when the output is to a
  1057. terminal, and another is most useful when the output is a file or a
  1058. pipe, then it is usually best to make the default behavior the one that
  1059. is useful with output to a terminal, and have an option for the other
  1060. behavior.
  1061.    Compatibility requires certain programs to depend on the type of
  1062. output device.  It would be disastrous if `ls' or `sh' did not do so in
  1063. the way all users expect.  In some of these cases, we supplement the
  1064. program with a preferred alternate version that does not depend on the
  1065. output device type.  For example, we provide a `dir' program much like
  1066. `ls' except that its default output format is always multi-column
  1067. format.
  1068.    It is a good idea to follow the POSIX guidelines for the
  1069. command-line options of a program.  The easiest way to do this is to use
  1070. `getopt' to parse them.  Note that the GNU version of `getopt' will
  1071. normally permit options anywhere among the arguments unless the special
  1072. argument `--' is used.  This is not what POSIX specifies; it is a GNU
  1073. extension.
  1074.    Please define long-named options that are equivalent to the
  1075. single-letter Unix-style options.  We hope to make GNU more user
  1076. friendly this way.  This is easy to do with the GNU function
  1077. `getopt_long'.
  1078.    One of the advantages of long-named options is that they can be
  1079. consistent from program to program.  For example, users should be able
  1080. to expect the "verbose" option of any GNU program which has one, to be
  1081. spelled precisely `--verbose'.  To achieve this uniformity, look at the
  1082. table of common long-option names when you choose the option names for
  1083. your program.  The table is in the file `longopts.table'.
  1084.    If you use names not already in the table, please send
  1085. `gnu@prep.ai.mit.edu' a list of them, with their meanings, so we can
  1086. update the table.
  1087.    It is usually a good idea for file names given as ordinary arguments
  1088. to be input files only; any output files would be specified using
  1089. options (preferably `-o').  Even if you allow an output file name as an
  1090. ordinary argument for compatibility, try to provide a suitable option
  1091. as well.  This will lead to more consistency among GNU utilities, so
  1092. that there are fewer idiosyncracies for users to remember.
  1093.    Programs should support an option `--version' which prints the
  1094. program's version number on standard output and exits successfully, and
  1095. an option `--help' which prints option usage information on standard
  1096. output and exits successfully.  These options should inhibit the normal
  1097. function of the command; they should do nothing except print the
  1098. requested information.
  1099. File: standards.info,  Node: Documentation,  Next: Releases,  Prev: User Interfaces,  Up: Top
  1100. Documenting Programs
  1101. ********************
  1102.    Please use Texinfo for documenting GNU programs.  See the Texinfo
  1103. manual, either the hardcopy or the version in the GNU Emacs Info
  1104. subsystem (`C-h i').  See existing GNU Texinfo files (e.g. those under
  1105. the `man/' directory in the GNU Emacs Distribution) for examples.
  1106.    The title page of the manual should state the version of the program
  1107. which the manual applies to.  The Top node of the manual should also
  1108. contain this information.  If the manual is changing more frequently
  1109. than or independent of the program, also state a version number for the
  1110. manual in both of these places.
  1111.    The manual should document all command-line arguments and all
  1112. commands.  It should give examples of their use.  But don't organize
  1113. the manual as a list of features.  Instead, organize it by the concepts
  1114. a user will have before reaching that point in the manual.  Address the
  1115. goals that a user will have in mind, and explain how to accomplish
  1116. them.  Don't use Unix man pages as a model for how to write GNU
  1117. documentation; they are a bad example to follow.
  1118.    The manual should have a node named `PROGRAM Invocation', `PROGRAM
  1119. Invoke' or `Invoking PROGRAM', where PROGRAM stands for the name of the
  1120. program being described, as you would type it in the shell to run the
  1121. program.  This node (together with its subnodes if any) should describe
  1122. the program's command line arguments and how to run it (the sort of
  1123. information people would look in a man page for).  Start with an
  1124. `@example' containing a template for all the options and arguments that
  1125. the program uses.
  1126.    Alternatively, put a menu item in some menu whose item name fits one
  1127. of the above patterns.  This identifies the node which that item points
  1128. to as the node for this purpose, regardless of the node's actual name.
  1129.    There will be automatic features for specifying a program name and
  1130. quickly reading just this part of its manual.
  1131.    If one manual describes several programs, it should have such a node
  1132. for each program described.
  1133.    In addition to its manual, the package should have a file named
  1134. `NEWS' which contains a list of user-visible changes worth mentioning.
  1135. In each new release, add items to the front of the file and identify
  1136. the version they pertain to.  Don't discard old items; leave them in
  1137. the file after the newer items.  This way, a user upgrading from any
  1138. previous version can see what is new.
  1139.    If the `NEWS' file gets very long, move some of the older items into
  1140. a file named `ONEWS' and put a note at the end referring the user to
  1141. that file.
  1142.    It is ok to supply a man page for the program as well as a Texinfo
  1143. manual if you wish to.  But keep in mind that supporting a man page
  1144. requires continual effort, each time the program is changed.  Any time
  1145. you spend on the man page is time taken away from more useful things you
  1146. could contribute.
  1147.    Thus, even if a user volunteers to donate a man page, you may find
  1148. this gift costly to accept.  Unless you have time on your hands, it may
  1149. be better to refuse the man page unless the same volunteer agrees to
  1150. take full responsibility for maintaining it--so that you can wash your
  1151. hands of it entirely.  If the volunteer ceases to do the job, then
  1152. don't feel obliged to pick it up yourself; it may be better to withdraw
  1153. the man page until another volunteer offers to carry on with it.
  1154.    Alternatively, if you expect the discrepancies to be small enough
  1155. that the man page remains useful, put a prominent note near the
  1156. beginning of the man page explaining that you don't maintain it and
  1157. that the Texinfo manual is more authoritative, and describing how to
  1158. access the Texinfo documentation.
  1159. File: standards.info,  Node: Releases,  Prev: Documentation,  Up: Top
  1160. Making Releases
  1161. ***************
  1162.    Package the distribution of Foo version 69.96 in a tar file named
  1163. `foo-69.96.tar'.  It should unpack into a subdirectory named
  1164. `foo-69.96'.
  1165.    Building and installing the program should never modify any of the
  1166. files contained in the distribution.  This means that all the files
  1167. that form part of the program in any way must be classified into "source
  1168. files" and "non-source files".  Source files are written by humans and
  1169. never changed automatically; non-source files are produced from source
  1170. files by programs under the control of the Makefile.
  1171.    Naturally, all the source files must be in the distribution.  It is
  1172. okay to include non-source files in the distribution, provided they are
  1173. up-to-date and machine-independent, so that building the distribution
  1174. normally will never modify them.  We commonly included non-source files
  1175. produced by Bison, Lex, TeX, and Makeinfo; this helps avoid unnecessary
  1176. dependencies between our distributions, so that users can install
  1177. whichever packages they want to install.
  1178.    Non-source files that might actually be modified by building and
  1179. installing the program should *never* be included in the distribution.
  1180. So if you do distribute non-source files, always make sure they are up
  1181. to date when you make a new distribution.
  1182.    Make sure that the directory into which the distribution unpacks (as
  1183. well as any subdirectories) are all world-writable (octal mode 777).
  1184. This is so that old versions of `tar' which preserve the ownership and
  1185. permissions of the files from the tar archive will be able to extract
  1186. all the files even if the user is unprivileged.
  1187.    Make sure that no file name in the distribution is more than 14
  1188. characters long.  Likewise, no file created by building the program
  1189. should have a name longer than 14 characters.  The reason for this is
  1190. that some systems adhere to a foolish interpretation of the POSIX
  1191. standard, and refuse to open a longer name, rather than truncating as
  1192. they did in the past.
  1193.    Don't include any symbolic links in the distribution itself.  If the
  1194. tar file contains symbolic links, then people cannot even unpack it on
  1195. systems that don't support symbolic links.  Also, don't use multiple
  1196. names for one file in different directories, because certain file
  1197. systems cannot handle this and that prevents unpacking the distribution.
  1198.    Try to make sure that all the file names will be unique on MS-DOG.  A
  1199. name on MS-DOG consists of up to 8 characters, optionally followed by a
  1200. period and up to three characters.  MS-DOG will truncate extra
  1201. characters both before and after the period.  Thus, `foobarhacker.c'
  1202. and `foobarhacker.o' are not ambiguous; they are truncated to
  1203. `foobarha.c' and `foobarha.o', which are distinct.
  1204.    Include in your distribution a copy of the `texinfo.tex' you used to
  1205. test print any `*.texinfo' files.
  1206.    Likewise, if your program uses small GNU software packages like
  1207. regex, getopt, obstack, or termcap, include them in the distribution
  1208. file.  Leaving them out would make the distribution file a little
  1209. smaller at the expense of possible inconvenience to a user who doesn't
  1210. know what other files to get.
  1211. Tag Table:
  1212. Node: Top
  1213. Node: Reading Non-Free Code
  1214. Node: Contributions
  1215. Node: Change Logs
  1216. Node: Compatibility
  1217. Node: Makefile Conventions
  1218. Node: Makefile Basics
  1219. 10114
  1220. Node: Utilities in Makefiles
  1221. 12005
  1222. Node: Standard Targets
  1223. 13441
  1224. Node: Command Variables
  1225. 19492
  1226. Node: Directory Variables
  1227. 22318
  1228. Node: Configuration
  1229. 28391
  1230. Node: Source Language
  1231. 33958
  1232. Node: Formatting
  1233. 35088
  1234. Node: Comments
  1235. 38378
  1236. Node: Syntactic Conventions
  1237. 41169
  1238. Node: Names
  1239. 44031
  1240. Node: Using Extensions
  1241. 45123
  1242. Node: Semantics
  1243. 46857
  1244. Node: Errors
  1245. 49825
  1246. Node: Libraries
  1247. 51028
  1248. Node: Portability
  1249. 52254
  1250. Node: User Interfaces
  1251. 55537
  1252. Node: Documentation
  1253. 58897
  1254. Node: Releases
  1255. 62655
  1256. End Tag Table
  1257.